<template>
  <a-drawer
    :title="'批量分组'"
    :maskClosable="true"
    :width="drawerWidth"
    placement="right"
    :closable="true"
    @close="handleCancel"
    :destroyOnClose="true"
    :visible="visible"
    style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">
    <a-spin :spinning="confirmLoading">
      <a-form-model
        ref="ruleForm"
        :model="formInfo"
        :label-col="$global.labelCol"
        :wrapper-col="$global.wrapperCol"
      >
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="组名名称" prop="departCode"  :maxLength="50">
              <a-select v-model="formInfo.groupId" placeholder="请选择分组">
                <a-select-option v-for="(item) in this.itemGrouplist" :key="item.id" :value="item.id">
                  {{item.group_name}}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
    <div class="drawer-bootom-button">
      <a-popconfirm title="确定放弃编辑？" @confirm="handleCancel" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="confirmLoading">提交</a-button>
    </div>
  </a-drawer>
</template>

<script>
  import { getAction, postAction } from '@/api/manage'
  import TagSelectOption from "@/components/TagSelect/TagSelectOption";
  import {getDepartlist, getItemTypeList, getItemGroupList } from "@/api/api";
  export default {
    name: 'HealthOrderItemEdit',
    components: {
      TagSelectOption
    },
    data () {
      return {
        visible: false,
        itemTypelist: [],
        itemGrouplist: [],
        confirmLoading: false,
        isChecked: false,
        formInfo: {
          orderItem: '',
          groupId: '',
          wx: ''
        },
        drawerWidth: 800,
        url: {
          saveInfo: '/system/healthOrderItem/updateGroup',
          getInfo: '/system/healthOrderItem/info'
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit()
      },
      edit (record) {
        this.$objToOverride(this.formInfo, record)
        if (this.formInfo.id) {
          getAction(this.url.getInfo, { 'id': record.id }).then(res => {
            this.$nextTick(() => {
              this.formInfo = res.result.data
              if(this.formInfo.areaId==0){
                 this.isChecked = true;
              }else{
                this.isChecked = false;
              }
            })
          })
        }else{
          this.formInfo.forsex = 2
          this.formInfo.isEmpty = 1
          this.formInfo.virginDisabled = 0
          this.formInfo.isfee = 0
          this.formInfo.isEnable = 1
        }
        this.visible = true
      },
      // 确定
      handleSubmit () {
        // 触发表单验证
        this.confirmLoading = true
        this.$refs.ruleForm.validate(valid => {
          console.log(valid)
          if (valid) {
            postAction(this.url.saveInfo, this.formInfo).then(res => {
              this.$message.success(res.content)
              this.$emit('ok', this.formInfo)
              this.close()
            }).finally(() => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      checkIs(item){
          if(event.target.checked){
            this.$message.success('000')
           this.formInfo.areaId = '0'
          }else{
            this.formInfo.areaId = undefined
        }
      },
      // 关闭
      handleCancel () {
        this.close()
      },
      getdepartList(){
        getItemGroupList({ }).then((res) => {
          const data = res.result.data
          this.itemGrouplist = data
        })
      },
      getItemTypeList(){
        getItemTypeList({ }).then((res) => {
          const data = res.result.data
          this.itemTypelist = data
        })
      },
      close () {
        this.$refs.ruleForm.resetFields()
        this.$objToReset(this.formInfo)
        this.$emit('close')
        this.visible = false
      },
      show(record){
        this.visible=true
        this.formInfo.orderItem = record
        this.getdepartList()
      },
      editorOk (val) {
        this.formInfo.content = val
      }
    }
  }
</script>
